using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using au.Swindles;
using LoanApprovalClient.CustomerService;

namespace LoanApprovalClient
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblLoginError.Text = string.Empty;
        }

        protected override void OnInit(EventArgs e)
        {
            btnSubmit.Click += new EventHandler(btnSubmit_Click);
            btnLogin.Click += new EventHandler(btnLogin_Click);
            base.OnInit(e);
        }

        void btnLogin_Click(object sender, EventArgs e)
        {
            string username = Utilities.getString(txtUsername.Text);
            string password = Utilities.getString(txtPassword.Text);

            Customer customer = BLQuoteAdmin.BLQuoteAdmin.validateCustomerLogin(username, password);
            if (customer != null)
            {
                Response.Redirect("./QuoteDetails.aspx?id=" + customer.CusomerID);
            }
            else
            {
                lblLoginError.Text = "Invalid Login";
            }
            
        }

        void btnSubmit_Click(object sender, EventArgs e)
        {
            string customerNumber = Utilities.getString(txtCustomerNumber.Text);
            string customerName = Utilities.getString(txtCustomerName.Text);
            decimal assetValue = Utilities.getDecimal(txtAssetValue.Text);
            decimal annualIncome = Utilities.getDecimal(txtAnnualIncome.Text);
            decimal annualExpenses = Utilities.getDecimal(txtAnnualExpenses.Text);
            decimal disposableIncome = annualIncome - annualExpenses;
            decimal loanAmount = Utilities.getDecimal(txtLoanAmount.Text);
            decimal loanTerm = Utilities.getDecimal(txtLoanTerm.Text);
            decimal loanIntrest = 6.0M;
            string prptyType = Utilities.getString(drpPropertyType.SelectedItem.Value);
            decimal prptySize = Utilities.getDecimal(txtPropertySize.Text);
            int prptyYearBuilt = Utilities.getInt32(txtPropertyBuilt.Text);
            string prptyAddressLine1 = Utilities.getString(txtAddressLine1.Text);
            string prptyAddressLine2 = Utilities.getString(txtAddressLine2.Text);
            string prptySuburb = Utilities.getString(txtSuburb.Text);
            string prptyState = Utilities.getString(txtState.Text);
            int prptyPostcode = Utilities.getInt32(txtPostcode.Text);
            string errorMessage = string.Empty;

            //call main process url
            LoanMainService.clientLoanMainPortTypeClient loanMainClient = new LoanApprovalClient.LoanMainService.clientLoanMainPortTypeClient();
            loanMainClient.applyForQuote(out errorMessage, customerNumber, customerName, disposableIncome, loanAmount,
                loanTerm, loanIntrest, prptyType, prptySize, prptyYearBuilt, prptyAddressLine1, prptyAddressLine2
                , prptySuburb, prptyState, prptyPostcode);

            string quoteNumber = "TEST";

        }
    }
}
